#include <stdio.h>
#include <unistd.h>

#define BUFFSIZE 32
int main (int argc, char **argv)
{
	FILE *fp = NULL;
	char c = 0;
	char buf[BUFFSIZE] = {0};
	
	if (argc < 2) {
		return -1;
	}
	//打开文件, 返回文件流
	fp = fopen (argv[1], "r");
	if (NULL == fp) {
		printf ("fopen failed!\n");
		return -1;
	}
	while (1) {
#if 0
		//第一次读取一个字符, 读完之后, 文件流会自动向后偏移
		c = fgetc (fp);
#endif
		//按行读取
		if (fgets (buf, BUFFSIZE, fp) == NULL) {
			//读出错或者读到eof
			if (ferror(fp)) {
				fprintf (stderr, "fgetc () error!\n");
				fclose (fp);
				return -1;
			}
			break;
		}
		fputs (buf, stdout);
		sleep (1);
	}
	fclose (fp);
	return 0;
}
